﻿using System;
using System.Collections.Generic;
using System.Text;
using DevExpress.XtraEditors;
using System.Data;
using DevExpress.XtraEditors.Controls;

namespace VietKinsNutrition.Common
{
    public class UserComboBoxItem
    {
        private string sValue;

        private string sDisplaytext;

        UserComboBoxItem(string sv, string sd)
        {
            sValue = sv;
            sDisplaytext = sd;
        }

        public override string ToString()
        {
            return sDisplaytext;
        }

        public string Value
        {
            get { return sValue; }
        }

        public string Display
        {
            get { return sDisplaytext; }
        }

        public static void SetItem(ComboBoxEdit combo, DataTable dt_source, string value, string display)
        {
            foreach (DataRow dr in dt_source.Rows)
            {
                combo.Properties.Items.Add(new UserComboBoxItem(dr[value].ToString(), dr[display].ToString()));
            }
        }

        public static string GetItemValue(ComboBoxEdit combo)
        {
            return ((UserComboBoxItem)combo.SelectedItem).Value;
        }

        public static void SelectItem(ComboBoxEdit combo, string svalue)
        {
            foreach(object item in combo.Properties.Items)
            {
                if ((((UserComboBoxItem)item).Value) == svalue)
                    combo.SelectedItem = item;
            }
        }
    }
}
